require(['./config'], () => {
  require(['swiper', 'jquery', 'Shortcut'], (Swiper, $, Shortcut) => {
    new Swiper('.swiper-container', {
      loop: true, // 循环模式选项
      effect: 'fade',
      autoplay: true,

      // 如果需要分页器
      pagination: {
        el: '.swiper-pagination',
      },

      // 如果需要前进后退按钮
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
    })

    class Index {
      constructor () {
        this.loadPublic()
        this.switchNotice()
      }

      loadPublic () {
        $('.shortcut').load('/HTML/shortcut.html')
        $('.header').load('/HTML/header.html')
        $('.footer').load('/HTML/footer.html')
        $('.sidebar').load('/HTML/sidebar.html',()=>{
          new Shortcut
        })
        $('.category').load('/HTML/nav.html', () => {
          this.showNavMoreEvent()
        })
      }

      showNavMoreEvent () {
        $('.category-item')
          .on('mouseenter', function () {
            $(this).addClass('active')
          })
          .on('mouseleave', function () {
            $(this).removeClass('active')
          })
      }

      switchNotice () {
        const $notice = $('.p-notice-list')
        $notice.children('li').eq(0).clone().appendTo($notice)
        const length = $notice.children('li').length
        setInterval(function () {
          let top = parseInt($notice.css('top'))
          top -= 43
          // $notice.css('top', top)
          $notice.animate({
            top: top
          }, function () {
            if (top <= -43 * (length - 1)) {
              $notice.css('top', 0)
            }
          })
        }, 2500)

      }
    }

    new Index()
  })
})
